package com.yiwyn.Behavioral.cor.pro.domain;


import com.yiwyn.Behavioral.cor.pro.exception.CtrctException;
import com.yiwyn.Behavioral.cor.pro.handle.base.AbstractContractHandle;
import com.yiwyn.Behavioral.cor.pro.handle.VariableHandle;
import com.yiwyn.Behavioral.cor.pro.handle.WaterMarkHandle;

import java.util.ArrayList;
import java.util.List;

public class ContractChain {

    List<AbstractContractHandle> handles = new ArrayList<>();
    private final Contract contract = new Contract();


    public ContractChain watermarker() {
        handles.add(WaterMarkHandle.getInstance());
        return this;
    }

    public ContractChain content() {
        handles.add(VariableHandle.getInstance());
        return this;
    }

    public Contract finished() {
        try {
            for (AbstractContractHandle handle : handles) {
                handle.doHandle(contract);
            }
        } catch (CtrctException e) {
            System.out.println(e.getMessage());
        }
        return contract;
    }


}
